package graph.paint.text;

import graph.Edge;
import graph.Node;
import graph.paint.NodePainter;
import graph.paint.ViewPort;

import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;

public class GeoPainter implements graph.paint.EdgePainter<String,Object>, NodePainter<String> {

	private int radius;

	public GeoPainter(int radius) {
		this.radius = radius;
	}
	@Override
	public void paint(GC gc, Edge<String,Object> edge, ViewPort viewPort, NodePainter<String> nodePainter) {
		double dx = edge.b.pos.x - edge.a.pos.x;
		double dy = edge.b.pos.y - edge.a.pos.y;
		double dl = Math.sqrt(dx*dx+dy*dy);
		double rr = viewPort.realLength(radius);
		double rx = rr*dx/dl;
		double ry = rr*dy/dl;
		
		int[] posa = viewPort.viewPos(edge.a.pos.x + rx, edge.a.pos.y + ry);
		int[] posb = viewPort.viewPos(edge.b.pos.x - rx, edge.b.pos.y - ry);
		gc.drawLine(posa[0], posa[1], posb[0], posb[1]);
	}

	@Override
	public void paint(GC gc, ViewPort viewPort, Node<String> node) {
		int[] pos = viewPort.viewPos(node.pos.x, node.pos.y);
		gc.drawOval(pos[0]-radius, pos[1]-radius, 2*radius, 2*radius);
	}

	@Override
	public int[] boundary(GC gc, ViewPort viewPort, Node<String> node,
			double xdir, double ydir) {
		return null;
	}


}
